package com.AAA.service.Impl.mht;

import com.AAA.dao.mht.ITmhtPlaneMapper;
import com.AAA.dao.mht.ITmhtRecondMapper;
import com.AAA.dao.mht.ITmhtRecordMapper;
import com.AAA.entity.MyPage;
import com.AAA.entity.mht.TMhtPlane;
import com.AAA.entity.mht.TMhtRecond;
import com.AAA.entity.mht.TMhtRecord;
import com.AAA.service.mht.ITmhtRecondService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class TmhtRecondServiceImpl implements ITmhtRecondService {
    @Autowired
    private ITmhtRecondMapper mapper;
    @Autowired
    private ITmhtPlaneMapper planeMapper;
    @Override
    public boolean byid(Integer id) {
        TMhtRecond tMhtRecond = mapper.byid(id);
        if (tMhtRecond!=null){
            return true;
        }
        return false;
    }

    @Override
    public boolean add(HttpServletRequest request) {
        String yqcode = request.getParameter("yqcode");
        TMhtPlane tMhtPlane = new TMhtPlane();
        tMhtPlane.setCode(yqcode);
        List<TMhtPlane> select = planeMapper.select(tMhtPlane);
        Integer pid = select.get(0).getId();
        Integer rid = Integer.valueOf(request.getParameter("id"));
        String recond = request.getParameter("recond");
        String remark = request.getParameter("remark");
        Integer uid = Integer.valueOf(request.getParameter("uid"));
        TMhtRecond tMhtRecond = new TMhtRecond();
        tMhtRecond.setRecond(recond);
        tMhtRecond.setRemark(remark);
        tMhtRecond.setRid(rid);
        tMhtRecond.setPid(pid);
        tMhtRecond.setCreateby(uid);
        tMhtRecond.setUpdateby(uid);
        tMhtRecond.setCreatetime(new Date());
        tMhtRecond.setUpdatetime(new Date());
        int insert = mapper.insert(tMhtRecond);
        if (insert>0){
            return true;
        }
        return false;
    }

    @Override
    public PageInfo query(MyPage myPage, String rname, String pname) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        List<Map<String, Object>> query = mapper.query(rname, pname);
        PageInfo pageInfo = new PageInfo(query);
        return pageInfo;
    }

    @Override
    public boolean edit(TMhtRecond tMhtRecond) {
        tMhtRecond.setUpdatetime(new Date());
        int i = mapper.updateByPrimaryKeySelective(tMhtRecond);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean del(Integer id) {
        int i = mapper.deleteByPrimaryKey(id);
        if (i>0){
            return true;
        }
        return false;
    }
}
